#!/user/bin/env node

const log = console.log,
      fs = require('fs'),
      ugid = process.argv[2],
      file = process.argv[3];
let uid,gid;

if(process.argv.length === 2){
  console.error('请输入正确命令行参数！');
  process.exit(1);
}else if(!fs.existsSync(file)){
  console.error(`${file} not exist!`);
  process.exit(2);
}
try{
  let ugarr = ugid.split(':');
  log(ugarr);
  uid = Number(ugarr[0]);
  gid = Number(ugarr[1]);
  log(uid);
  log(gid);
  fs.chownSync(file,uid,gid);
  log('修改成功！');
  process.exit(3);
}catch(e){
  console.error(e.message);
  process.exit(4);
}
